package com.youshang520i.demo.annotation.controller;

import org.springframework.stereotype.Component;
import org.springframework.web.HttpRequestHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author youshang
 */
@Component("/myHttpRequestHandle") //试一下不设置名称
public class MyHttpRequestHandle implements HttpRequestHandler {
    @Override
    public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter writer = response.getWriter();
        writer.write("myHttpRequestHandle !!!");
        writer.flush();
        writer.close();
        //设置返回页面
        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }
}
